package it.uniroma2.structure;

import java.io.Serializable;

public class PartnerLink implements Serializable{

	private Service serviceRef;
	private String name;
	private String partenerLinkType;
	private boolean myRole;
	private String role;

	private final String partnerTag = "bpel:partnerLink";
	
	public PartnerLink(String name, String partenerLinkT, boolean myrole, String role){
		this.name = name;
		this.partenerLinkType = partenerLinkT;
		this.myRole = myrole;
		this.role = role;
		this.serviceRef = null;
	}
	

	public Service getServiceRef() {
		return serviceRef;
	}

	public void setServiceRef(Service serviceRef) {
		this.serviceRef = serviceRef;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPartenerLinkType() {
		return partenerLinkType;
	}

	public void setPartenerLinkType(String partenerLinkType) {
		this.partenerLinkType = partenerLinkType;
	}

	public boolean isMyRole() {
		return myRole;
	}

	public void setMyRole(boolean myRole) {
		this.myRole = myRole;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(this.name.equals(((PartnerLink)obj).getName()) && this.partenerLinkType.equals(((PartnerLink)obj).getPartenerLinkType()) && this.role.equals(((PartnerLink)obj).getRole())){
			return true;
		}else{
			return false;
		}
	}
	
	@Override
	public String toString() {
		String output = "name=\"" + this.name + "\" partnerLinkType=\"" + this.partenerLinkType + "\" ";
		if(this.myRole){
			output = output + "myRole=\"" + this.role + "\"";
		}else{
			output = output + "partnerRole=\"" + this.role + "\"";
		}
		return output;
	}
	
	public String toBPEL(){
		return "<" + this.partnerTag + " " + this.toString() + "/>\n";
	}
}
